<?php
namespace PsiFramework\Classes\Util\Parameters\DAO;

import("Classes.DAO.AbstractDAO");
import("Classes.Util.Parameters.ApplicationConfiguration");

use \PsiFramework\Classes\DAO\AbstractDAO;
use \PsiFramework\Classes\Util\Database\Filters\QueryFilter;
use \PsiFramework\Classes\Util\Database\Query\SqlColumn;
use \PsiFramework\Classes\Util\Database\Query\SqlOperation;
use \PsiFramework\Classes\Util\Database\Query\SqlValue;
use \PsiFramework\Classes\Util\Parameters\ApplicationConfiguration;

/**
 * AlloMedia
 * Portail des professionnels
 *
 * @author Rémi San
 * @version beta
 */

/**
 *
 *
 * @package DAO
 */
class ApplicationConfigurationDAO extends AbstractDAO
{

    protected static $_singleton = null;

    public function retrieveByName(/*string*/ $name, /*bool*/ $checkSecurity=true)
    {

        $colNom = new SqlColumn("application_name");
        $sqlValue = new SqlValue($name);

        $op = new SqlOperation(SqlOperation::$equal);
        $op->addParameter($colNom);
        $op->addParameter($sqlValue);

        $result = $this->retrieveAll(new QueryFilter($op), null, $checkSecurity);

        if (!is_null($result) && count($result)==1) {
            return $result[0] ;
        } else {
            return null ;
        }
    }

    /**
     * Function to be called instead of the constructor.
     *
     * @return ApplicationConfigurationDAO    instance
     */
    public static function getInstance($objectParameters)
    {

        if (self::$_singleton==null) {
            self::$_singleton =
                new ApplicationConfigurationDAO($objectParameters);
        }

        return self::$_singleton;
    }

}
